package com.yaowk.system.server.service.base;

import com.yaowk.system.api.model.Resource;
import java.lang.Long;
import com.yaowk.system.server.entity.SysResource;
import org.springframework.beans.factory.annotation.Autowired;
import com.yaowk.system.server.service.IResourceService;
import com.yaowk.common.db.BaseServiceImpl;
import com.yaowk.system.server.dao.ResourceDao;
import java.lang.String;

public abstract class ResourceServiceBase extends BaseServiceImpl<Resource, SysResource, Long> implements IResourceService {

	@Autowired
	private ResourceDao dao;

	@Override protected ResourceDao getDao() {
	return dao;
	}

	@Override
	public Resource entity2Model(SysResource entity) {
		Resource model = null;
		if(isNotEmpty(entity)){
			model = new Resource();
			model.setId(entity.getId());
			model.setMethod(entity.getMethod());
			model.setResource(entity.getResource());
			model.setName(entity.getName());
		}
		return model;
	}

	@Override
	public SysResource model2Entity(Resource model) {
		SysResource entity = null;
		if(isNotEmpty(model)){
			entity = new SysResource();
			entity.setId(model.getId());
			entity.setMethod(model.getMethod());
			entity.setResource(model.getResource());
			entity.setName(model.getName());
		}
		return entity;
	}

	@Override
	public SysResource updateParams(Resource model) {
		SysResource entity = dao.findOne(model.getId());
		if(isNotEmpty(model.getMethod()))
			entity.setMethod(model.getMethod());
		if(isNotEmpty(model.getResource()))
			entity.setResource(model.getResource());
		if(isNotEmpty(model.getName()))
			entity.setName(model.getName());
		return entity;
	}


}